<?php

    global $mikron;

    $patientcode = isset($_GET['code'])?$_GET['code']:$wizard['code'];

    $patient = new patient_class();
    if(!$mikron->Tools->IsNullOrEmpty($patientcode))
    {        
        $patient->getdata($patientcode);
    }

    class patient_class
    {

        public $id = "";
        public $fio = "";
        public $birthday = "";
        public $cardnumber = "";
        public $cardid = "";
        public $state = "";
        public $errortext = "";

        function getdata($code)
        {

            global $patientcode;
            $this->id = $code;

            $xmlfile = CallSoap('GetPatientCard', $code);

            // XML с данными расписания
            $dom1 = new DomDocument();
            $dom1->loadXML($xmlfile);

            $patients = $dom1->getElementsByTagName('patient');

            // Заполнение классов из XML
            foreach($patients as $patient)
            {
                $id = $patient->getAttribute('id');
                $patientcode = $id;
                $fio = $patient->getAttribute('fio');
                $birthday = $patient->getAttribute('birthday');
                $cardnumber = $patient->getAttribute('cardnumber');
                $cardid = $patient->getAttribute('cardid');
                $state = $patient->getAttribute('state');
                // $fio = i conv("UTF-8", "WINDOWS-1251", $fio);
                $this->id = $id;
                $this->fio = $fio;
                $this->birthday = $birthday;
                $this->cardnumber = $cardnumber;
                $this->cardid = $cardid;
                $this->state = $state;
            }
        }

    }

    // Дополнительные функции связанные с пациентами
    function showpacientinfo()
    {        
        global $patient;
        if(isset($patient) && ($patient->errortext == '') && ($patient->id != ''))
        {
            //startxwindow("Пациент", "");
            startttable("#e2ffb6");
            ?><span style="color: #85c326; font-size: .9em;"><?php
            echo $patient->fio;
            ?>
            <!-- br><br>Участок №<?php echo $patient->state;?> --><br>
            <br>Код пациента:<br>
            <?php
            $buf = $patient->id;
            $pcode = Array();
            $pcode[] = substr($buf, 0, 4);
            $pcode[] = substr($buf, 4, 4);
            $pcode[] = substr($buf, 8, 4);
            $pcode[] = substr($buf, 12, 4);
            echo "<nobr>".implode("-", $pcode)."</nobr>";
            ?></span><?php
            //endxwindow();
            endttable("#e2ffb6");
        }
    }

?>